// 对request的二次封装
const {
  baseURL
} = require('./env').prod
// 专属域名
const vip = "Zhangqq"
module.exports = {
  // 封装wxwx.request不支持,所有咱们的用promise包一层,让它支持promise
  request: function (url, method = "GET", data = {}, isSunDomain = true) {
    // url=基地址baseURL+专属域名vip+业务接口url
    if (isSunDomain) {
      url = `${baseURL}/${vip}/${url}`
    } else {
      url = `${baseURL}/${url}`
    }
    return new Promise((resolve, reject) => {
      // 请求之前显示的loading
      wx.showLoading({
        title: '玩命加载中...',
      })
      wx.request({
        url,
        method,
        data,
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success(res) {
          // 成功返回,隐藏loading
          wx.hideLoading()
          resolve(res.data)
        },
        fail(error) {
          reject(error)
        }
      })
    })
  }

}